/**
 * 
 */
package co.fitstart.mobile.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.support.Page;

import co.fitstart.entity.credit.order.CreditOrder;
import co.fitstart.entity.user.User;
import co.fitstart.mobile.dao.support.CreditOrderDaoSupport;
import co.fitstart.mobile.service.CreditOrderService;

/**
 * @author Guangli Yan
 *
 */
@Service("creditOrderService")
public class CreditOrderServiceImpl implements CreditOrderService{

	@Autowired
	private GenericDaoSupport genericDaoSupport;
	
	@Autowired
	private CreditOrderDaoSupport creditOrderDaoSupport;
	
	/* (non-Javadoc)
	 * @see co.fitstart.mobile.service.CreditOrderService#list(co.fitstart.entity.user.User)
	 */
	public List<CreditOrder> list(User user) {
		
		List<CreditOrder> creditOrders = creditOrderDaoSupport.list(user, 0 , 7);
		
		return creditOrders;
	}

	/* (non-Javadoc)
	 * @see co.fitstart.mobile.service.CreditOrderService#list(co.fitstart.entity.user.User, com.demo2do.core.support.Page)
	 */
	public List<CreditOrder> list(User user, Page page) {

		List<CreditOrder> result = creditOrderDaoSupport.list(user, page.getBeginIndex(), page.getEveryPage());
		
		page.calculate(result.size());
		
		return result.size() > page.getEveryPage() ? result.subList(0, page.getEveryPage()) : result;
	}

	/* (non-Javadoc)
	 * @see co.fitstart.mobile.service.CreditOrderService#load(java.lang.Long)
	 */
	@Override
	public CreditOrder load(Long creditOrderId) {

		CreditOrder creditOrder = genericDaoSupport.load(CreditOrder.class, creditOrderId);
		
		return creditOrder;
	}

}
